package com.lwz.startdemo.splash

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.dopdxd.combase.base.BaseActivity
import com.lwz.startdemo.MainActivity
import com.lwz.startdemo.MainViewModel
import com.lwz.startdemo.MainViewModelFactory
import com.lwz.startdemo.MyObserver
import com.lwz.startdemo.Person
import com.lwz.startdemo.databinding.ActivitySplashBinding
import kotlin.concurrent.thread
import kotlin.math.abs

/**
 * @Description: 开屏页面
 * @Author: chad
 * @CreateDate: 2025/2/13 10:00
 * @Version: 1.0
 */
class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding::inflate){
    lateinit var viewModel: MainViewModel

    override fun isImmersion(): Boolean {
        return true
    }
    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

//        viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        viewModel = ViewModelProvider(this, MainViewModelFactory(10)).get(MainViewModel::class.java)
        initData()
        lifecycle.addObserver(MyObserver(lifecycle))
    }

    override fun initListener() {
        super.initListener()

        mBinding.btn1.setOnClickListener {
            val intent = Intent(this, MainActivity::class.java)
            intent.putExtra("person",Person("nihao"))
            startActivity(intent)
            finish()
        }
        mBinding.btn2.setOnClickListener {
            viewModel.plusOne()
        }
        viewModel.counter.observe(this) { count->
            refreshui(count)
        }
    }

    private fun refreshui(value:Int) {
//        mBinding.tv1.text = viewModel.counter.value.toString()
        mBinding.tv1.text = value.toString()
    }


    private fun initData() {
       thread {
           Log.i("ycg","ddd")
       }

        val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape", "Watermelon")
        val newList = list.map { fruit: String -> fruit.toUpperCase() }
        for (fruit in newList) {
            println(fruit)
        }

    }


    override fun onDestroy() {
        super.onDestroy()
        overridePendingTransition(0, 0)
    }


}